package com.crayon2f.test;

import java.io.File;
import java.util.Objects;

public class RenameZKFile {

    public static void main(String[] args) {

        File file = new File("D:\\download\\file\\we_chat\\WeChat Files\\goufeifan273431277\\FileStorage\\File\\2023-05");
        File[] list = file.listFiles();
        for (File dir : Objects.requireNonNull(list)) {
            if (dir.isDirectory()) {
                File[] files = dir.listFiles();
                File[] requireNonNull = Objects.requireNonNull(files);
                int j = 1;
                for (File pic : requireNonNull) {
                    String name = pic.getName();
                    if (name.endsWith(".jpg")) {
                        File renameFile = new File(dir.getAbsolutePath() + File.separator + String.format("0%d.jpg", j));
                        if (!renameFile.exists()) {
                            pic.renameTo(renameFile);
                        }
                        j++;
                    }
                }
            }
        }
    }
}
